<template>
  <view class="demo-container">
    <!-- 基础用法 -->
    <view class="demo-block">
      <view class="demo-block__title">基础用法</view>
      <view class="demo-block__content">
        <fu-upload
          v-model:file-list="fileList1"
          action="https://api.example.com/upload"
          @success="onSuccess"
          @error="onError"
        />
      </view>
    </view>
    
    <!-- 图片上传 -->
    <view class="demo-block">
      <view class="demo-block__title">图片上传</view>
      <view class="demo-block__content">
        <fu-upload
          v-model:file-list="fileList2"
          action="https://api.example.com/upload"
          list-type="picture"
          accept="image/*"
          :limit="3"
          @exceed="onExceed"
        />
      </view>
    </view>
    
    <!-- 自定义上传按钮 -->
    <view class="demo-block">
      <view class="demo-block__title">自定义上传按钮</view>
      <view class="demo-block__content">
        <fu-upload
          v-model:file-list="fileList3"
          action="https://api.example.com/upload"
        >
          <fu-button type="primary">选择文件</fu-button>
        </fu-upload>
      </view>
    </view>
    
    <!-- 禁用状态 -->
    <view class="demo-block">
      <view class="demo-block__title">禁用状态</view>
      <view class="demo-block__content">
        <fu-upload
          v-model:file-list="fileList4"
          action="https://api.example.com/upload"
          disabled
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      fileList1: [],
      fileList2: [],
      fileList3: [],
      fileList4: []
    }
  },
  methods: {
    onSuccess(response, file, fileList) {
      uni.showToast({
        title: '上传成功',
        icon: 'success'
      })
    },
    onError(error, file, fileList) {
      uni.showToast({
        title: '上传失败',
        icon: 'error'
      })
    },
    onExceed(files, fileList) {
      uni.showToast({
        title: `最多只能上传3个文件`,
        icon: 'none'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.demo-container {
  padding: 20rpx;
}

.demo-block {
  margin-bottom: 30rpx;
  
  &__title {
    margin-bottom: 20rpx;
    font-size: var(--fu-font-size-lg);
    color: var(--fu-text-color);
  }
  
  &__content {
    background-color: #fff;
    padding: 30rpx;
    border-radius: var(--fu-radius-base);
  }
}
</style> 